package edu.seu.mart.dao.impl;

import edu.seu.mart.dao.BaseDao;
import edu.seu.mart.dao.IUserDao;

import edu.seu.mart.entity.Pager;
import edu.seu.mart.model.User;
import org.springframework.stereotype.Repository;

@Repository("userDao")
public class UserDao extends BaseDao<User> implements IUserDao {

	@Override
	public Pager<User> findUser() {
		return this.find("from User");
	}

    @Override
    public Pager<User> findUser(String name) {
        return this.find("from User where username = '" + name + "'");
    }

    @Override
    public User findUserByEmail(String email) {
        if (this.list("from User where email = '" + email + "'").isEmpty()) {
            return null;
        } else {
            return this.list("from User where email = '" + email + "'").get(0);
        }
    }

    @Override
    public User findUserByName(String username) {
        if (this.list("from User where username = '" + username + "'").isEmpty()) {
            return null;
        } else {
            return this.list("from User where username = '" + username + "'").get(0);
        }
    }
}
